import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../views/index.vue'
import IndexView from '../views/IndexViews/IndexView'
import EchartsZx from '../views/EchartsViews/EchartsZx'
import EchartsZz from '../views/EchartsViews/EchartsZz'
import EchartsZzs from '../views/EchartsViews/EchartsZzs'
import EchartsBz from '../views/EchartsViews/EchartsBz'
import EchartsBzs from '../views/EchartsViews/EchartsBzs'
Vue.use(VueRouter)
const routes = [
  {
   path:'/',
   name:'',
   component:Index,
   redirect:'/IndexView',
   children:[
    {
      path: '/IndexView',
      name: '首页',
      component:IndexView
    },
    {
      path: '/EchartsZx',
      name: '折线图',
      component:EchartsZx
    },
    {
      path: '/EchartsZz',
      name: '柱状图',
      component:EchartsZz,
      meta:{
        showfater: true
     },
      children:[
        {
          path: '/EchartsZz/EchartsZzs',
          name: '柱状图子',
          component:EchartsZzs,
          meta:{
            childrenUrl:'/EchartsZz'
         },
        }
      ]
    },
    {
      path: '/EchartsBz',
      name: '饼状图',
      component:EchartsBz,
      meta:{
        showfater: true
     },
      children:[
        {
          path: '/EchartsBz/EchartsBzs',
          name: '饼状图子页面',
          component:EchartsBzs,
          meta:{
            childrenUrl:'/EchartsBz'
         },
        }
      ]
    },

   ]
  },

]
//解决重复点击路由跳转报错
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//修改浏览器标题
router.beforeEach((to,from,next)=>{
  if(to.name){
    document.title = to.name
  }
  next()
})
export default router
